package com.sofwin.controller.contents;

import com.github.pagehelper.PageInfo;
import com.sofwin.pojo.CHistoryDetail;
import com.sofwin.pojo.CHistoryMain;
import com.sofwin.pojo.CInformationWithBLOBs;
import com.sofwin.pojo.CStock;
import com.sofwin.service.contents.CHistoryDetailService;
import com.sofwin.service.contents.CHistoryMainService;
import com.sofwin.service.contents.CompanyBasicSituationService;
import com.sofwin.service.contents.CstockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.ArrayList;
import java.util.List;

/**
 * @program: authority-management-system.git
 * @description: TODO
 * @author: Mr.Gao
 * @create: 2021-04-25 10:54
 **/
@Controller
@RequestMapping("/basic")
public class CompanyBasicSituationController {

    @Autowired
    private CompanyBasicSituationService service;

    @Autowired
    private CstockService cstockService;

    @Autowired
    private CHistoryMainService cHistoryMainService;

    @Autowired
    private CHistoryDetailService cHistoryDetailService;



    /**
    * @Description: 企业基本情况页面
    * @param cInformationWithBLOBs: 工商登记信息
    * @param cHistoryMain: 历史沿革
    * @param cHistoryDetail: 历史沿革-明细
    * @param cStock: 股东结构
    * @param model: 作用域
    * @return: String
    * @Author: Mr.Gao
    * @Date: 2021/4/26
    */
    @RequestMapping("baseInfo")
    public String baseInfo(CInformationWithBLOBs cInformationWithBLOBs, CHistoryMain cHistoryMain, CHistoryDetail cHistoryDetail,CStock cStock, Model model){
        //企业基本信息
        PageInfo<CInformationWithBLOBs> page = service.selectAll(cInformationWithBLOBs);
        model.addAttribute("data",page.getList());
        model.addAttribute("user",cInformationWithBLOBs);

        //股东结构
        if (page.getList()!=null){
            Integer id = page.getList().get(0).getId();
            CStock cc = new CStock();
            cc.setInfoId(id);

            PageInfo<CStock> page2 = cstockService.selectAll(cc);
            model.addAttribute("data2",page2.getList());
            model.addAttribute("user2",cStock);
        }

        //历史沿革
        if (page.getList()!=null) {
            Integer id = page.getList().get(0).getId();
            CHistoryMain cm = new CHistoryMain();
            cm.setInfoId(id);

            PageInfo<CHistoryMain> page3 = cHistoryMainService.selectAll(cm);
            model.addAttribute("data3", page3.getList());

            //历史沿革-明细
            List<List<CHistoryDetail>> detail = new ArrayList<>();
            for (int i = 0; i < page3.getList().size(); i++) {
                Integer id2 = page3.getList().get(i).getId();
                CHistoryDetail cd = new CHistoryDetail();
                cd.setMainId(id2);
                List<CHistoryDetail> page4 = cHistoryDetailService.selectAll(cd);
                detail.add(page4);
            }

            model.addAttribute("data4",detail);

        }


        return "c_information/contents/baseInfo";
    }

}
